    /********************************************************/
    /*                                                      */
    /*                                                      */
    /*         Copyright (C), 1993  SEIKO EPSON Corp.       */
    /*         ALL RIGHTS RESERVED                          */
    /*                                                      */
    /*                                                      */
    /*  file name : ungetc.c                                */
    /*                                                      */
    /*  Revision history                                    */
    /*      93/12/17    first release       S.Akaiwa        */
    /*      97/3/17	modified	    T.Katahira	    */
    /*			change function declaration	    */
    /*					to the ANSI style   */
    /*                                                      */
    /********************************************************/

#ifdef  UNIX
#include    "stdio.h"
#include    "smcvals.h"
#else
#include    <stdio.h>
#include    <smcvals.h>
#endif

int
ungetc(int iDat, FILE * fiStrmP)

    /********************************************************/
    /*                                                      */
    /*  The ungetc function pushs the character specified   */
    /*  by iDat back onto the input stream pointed to by    */
    /*  fiStrmP.                                            */
    /*  If stdin, stdout, stderr is not specified by        */
    /*  fiStrmP, this function returns EOF.                 */
    /*  This function can not call 2 times in succession.   */
    /*                                                      */
    /*      RETURN  Except EOF  ... Pushed back character   */
    /*              EOF         ... Error                   */
    /*                                                      */
    /*  <ANSI>                                              */
    /*      The ungetc function pushs the character back    */
    /*      onto the input stream.                          */
    /*                                                      */
    /*      RETURN  Except EOF  ... Pushed back character   */
    /*              EOF         ... Error                   */
    /*                                                      */
    /********************************************************/

    /* int     iDat    ;           character to pushed back */
    /* FILE    *fiStrmP;           pointer to target stream */
    {

     if(!_ISSTDIO(fiStrmP)){                /* check stream */
        return  (int)EOF;                 /* illegal stream */
     }

     if(fiStrmP == stdin){                  /* stream stdin */
        if(fiStrmP->_flg == _UGETY){ 
           return   (int)EOF;      /* unget character exist */
        }
        else {                     /* pushed back character */
           fiStrmP->_buf = (unsigned char)iDat;
           fiStrmP->_flg = _UGETY;
        }
     }

     return (int)iDat;      /* return pushed back character */
    }